/**
 * @class 银河星系数据代理
 * @author DuskyHuang 圣子
 * @description 提供深空天体（星云、星团）、银河系、河外星系、本星系群和本超星系群的相关数据和管理。
*/

import { Vec3 } from 'cc';
import { Proxy, decorators } from 'cfw';
import { StarSpectrum } from 'const';
import { UI } from 'notifications';
const { singleton } = decorators;
const { O, A, G, R, S } = StarSpectrum;

@singleton
export class DeepGalaxiesProxy extends Proxy {

    public get showClusters(): boolean { return this._show_clusters; }
    public get showNebulas(): boolean { return this._show_nebulas; }
    public get showGalaxies(): boolean { return this._show_galaxies; }
    public get showBlackHoles(): boolean { return this._show_black_holes; }

    declare public static readonly instance: DeepGalaxiesProxy;
    private constructor() { super(); }

    public getStateByName(name: string): boolean {
        switch (name) {
            case '星团': return this.showClusters;
            case '星云': return this.showNebulas;
            case '星系': return this.showGalaxies;
            case '黑洞': return this.showBlackHoles;
            default: return null;
        }
    }

    public static readonly MilkyWay = {
        THICKNESS: 0.05,
        GPUStars: {
            PARTICLE_NUM: 18000,
            SizesRange: [0.1, 0.15],
            ColorGradients: [
                [O, A], // 蓝白
                [S, A], // 红白
                [R, A], // 橙白
                [A, A], // 白白
                [S, G], // 红橙
            ]
        },
        CLouds: {
            LAYERS: 7,
            HIGHT: 0.2
        },
        /** @deprecated 考虑性能不再使用CPU-Instancing粒子改用GPU粒子 */
        InstancingStars: {
            TOTAL_NUM: 3000,
            DistRange: [1.0, 9.5],
            ScaleRange: [0.02, 0.03],
            ClampRange: [0.5, 2.5],
        },
        Structures: [
            ["银心黑洞", "Galactic Center Black Hole", new Vec3(0.0942, -2.33, -0.437), true],
            ["银核棒旋", "Galactic Bar", new Vec3(-0.180, -2.94, -1.09), false],
            ["银核棒旋", "Galactic Bar", new Vec3(0.444, -1.90, 0.300), false],
            ["猎户臂", "Orion Arm", new Vec3(-0.250, 0.399, -0.344), false],
            ["猎户臂", "Orion Arm", new Vec3(0.250, -0.253, 0.382), false],
            ["远三千秒差距臂", "Far 3kpc Arm", new Vec3(0.452, -2.81, 0.078), false],
            ["近三千秒差距臂", "Near 3kpc Arm", new Vec3(-0.273, -2.06, -1.02), false],
            ["人马臂", "Sagittarius Arm", new Vec3(0.877, -2.80, 0.842), true],
            ["船底臂", "Carina Arm", new Vec3(-1.40, -1.38, -2.86), true],
            ["英仙臂", "Perseus Arm", new Vec3(1.25, -1.80, 1.77), true],
            ["英仙臂", "Perseus Arm", new Vec3(-1.13, 0.971, -1.76), true],
            ["盾牌-南十字臂", "Scutum Arm", new Vec3(-0.749, -1.13, -1.63), true],
            ["半人马臂", "Centaurus Arm", new Vec3(-0.171, -5.49, -1.73), true],
            ["矩尺臂", "Norma Arm", new Vec3(-0.498, -1.77, -1.35), true],
            ["天鹅臂", "Cygnus Arm", new Vec3(1.70, -1.90, 2.55), false],
            ["新外臂", "New Outer Arm", new Vec3(-0.626, 1.92, -0.623), false],
        ]
    }

    public static readonly CommonDescriptions = {
        S: "属于本星系群的矮球状星系",
        I: "属于本星系群的矮不规则星系",
        E: "属于本星系群的矮椭球星系",
        SatE: "属于本星系群的矮椭圆状星系，也是银河系的一个卫星星系，主要由老年恒星组成。",
        SatI: "属于本星系群的矮不规则星系，也是银河系的一个卫星星系。",
        SatS: "属于本星系群的矮球状星系，也是银河系的一个卫星星系。",
        MSatS: "属于本星系群的矮球状星系，也是仙女座星系的一个卫星星系。",
        MSatE: "属于本星系群的矮椭球星系，也是仙女座星系的一个卫星星系。"
    };

    protected init(): void {
        this.on(CLUSTERS, (show: boolean) => this._show_clusters = show);
        this.on(NEBULAS, (show: boolean) => this._show_nebulas = show);
        this.on(GALAXIES, (show: boolean) => this._show_galaxies = show);
        this.on(BLACKHOLE, (show: boolean) => this._show_black_holes = show);
    }

    private _show_clusters: boolean = true;
    private _show_nebulas: boolean = true;
    private _show_galaxies: boolean = true;
    private _show_black_holes: boolean = true;
}

const { Stellar: { CLUSTERS, NEBULAS, GALAXIES, BLACKHOLE } } = UI;

export const deepGalaxy = DeepGalaxiesProxy.instance;